<?php

namespace App\Http\Controllers;

use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use InfyOm\Generator\Utils\ResponseUtil;
use Response;


class Controller extends BaseController
{
//    use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
    protected $_vd;

    protected function r_view($view, $data = [])
    {
        if (isset($_SERVER['HTTP_X_PJAX'])) {
            return view($view, $data);
        } else {
            $content = view('/root/head');
            $content .= view($view, $data);
            $content .= view('/root/foot');
            return $content;
        }
    }


    protected function getCategory()
    {
        $arr = config('imm', 'category');
        if (!empty($arr)) {
            $this->eachCategory($arr['category']);
        }
    }

    private function eachCategory($category)
    {
        foreach ($category as $cc) {
            $this->_vd['category'][$cc['id']] = str_pad('', $cc['level'] * 2, '--', STR_PAD_LEFT) . $cc['name'];
            if (!empty($cc['category'])) {
                $this->eachCategory($cc['category']);
            }
        }
    }

    public function sendResponse($result, $message)
    {
        return Response::json(ResponseUtil::makeResponse($message, $result));
    }

    public function sendError($error, $code = 200)
    {
        return Response::json(ResponseUtil::makeError($error), $code);
    }
}
